package com.atguigu.a_ip;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Demo {
    public static void main(String[] args) throws UnknownHostException {
        //获取当前主机的IP地址对象
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println("ip1 = " + ip1);//LAPTOP-28I8FM6J/192.168.16.61


        //static InetAddress getByName(String host)
        InetAddress ip2 = InetAddress.getByName("192.168.16.37"); //String --> InetAddress
        System.out.println("ip2 = " + ip2);///192.168.16.37

        System.out.println("ip2.getHostName() = " + ip2.getHostName());


        InetAddress ip3 = InetAddress.getByName("aFengLiuGou");
        System.out.println("ip3 = " + ip3);//aFengLiuGou/192.168.16.40

        System.out.println("ip3.getHostAddress() = " + ip3.getHostAddress());
    }
}
